package commands;

import java.io.PrintWriter;

import server.AccessDeniedException;
import server.RefrensMonitor;
import server.Subject;

public class ReadAction implements Action {

	private PrintWriter pw;
	private Subject sub;
	private String line;

	public ReadAction(PrintWriter pw, Subject sub, String string) {
		this.pw = pw;
		this.sub = sub;
		this.line = string;
	}

	@Override
	public void perform() {
		int rec  = 0;
		try{
			rec = Integer.parseInt(line);			
		}catch (NumberFormatException e) {
			pw.println("Wrong syntax command.");
			return;
		}
		String message = " ";
		try {
			message = RefrensMonitor.getInstance().read(sub, rec);
		} catch (AccessDeniedException e) {
			pw.println("Access Denied");
			return;
		}
		pw.println(message);
		
	}

}
